<?php
namespace WebAdmin\Controller;
use WebAdmin\Controller\BaseController;
class PositionApplyController extends BaseController {
	
	//ThinkPHP的构造函数
	public function _initialize() {
		//自动加载的类
		parent::_initialize();
		new \Org\Admin_autoload();
	}
	
    public function index(){
    	$this->assign('page_title','职位申请列表');
    	$this->display();
    }

    //Ajax获取数据
    public function getData()
    {
        header("Content-type:text/html;charset=utf-8");
        $DataModel = M('position_apply');
        $items = array();
        $page = (int)$_GET['page'];
        $items['page'] = $page>0 ? $page :1;
        $items['records'] = $DataModel->count();
        $limit = $_GET['rows'] ? (int)$_GET['rows']: 20;
        $items['total'] = ceil($items['records']/$limit);
        $list=$DataModel->page($page)->limit($limit)->select();
        foreach($list as $k=>$v){
            //查职位信息
            $position_id=$v['position_id'];
            $position_info=M('Positions')->field('name')->find();
            $list[$k]['position_name']=$position_info['name'];
            $list[$k]['resume'] = "http://".FRONT_SITE_NAME.$v['resume'];
        }
        //dump($list);exit;

        //$DataModel = D("Positions");
        //$list = $DataModel->select();
        $items['rows'] = $list;
    	$this->ajaxReturn($items);
    }

 

    //单条记录删除
    public function delete(){
        if(!empty($_POST)) {
            $id=intval($_POST['id']);
            $Model = D("PositionApply");
            $item = $Model->where("id=".$id)->find();
            $result = $Model->delete($id);
            if($result){
            	$root_path = dirname(dirname(dirname(dirname(__FILE__))));
            	unlink($root_path."/www".str_replace("http://".FRONT_SITE_NAME,"",$item['resume']));
                header("Content-type: text/html; charset=utf-8");
                echo "<script>layer.closeAll(); \$table.trigger(\"reloadGrid\");</script>";exit;
            }
        }
        $this->display();
    }


}